<?php
class ZnvusersController extends AppController {

	var $name = 'Znvusers';
	var $helpers = array('Html', 'Form');
/*
	function index() {
		$this->Znvuser->recursive = 0;
		$this->set('znvusers', $this->paginate());
	}
    */
    function index($id_dv=null) {
		$this->Znvuser->recursive = 0;
		$this->set('znvusers', $this->paginate(array('donvi_id'=>$id_dv)));
        //print_r($nhanviens);
        $tendv=$this->Znvuser->query("select id,tendv from donvis where id=".$id_dv);
        $this->set(compact('id_dv','tendv'));
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid Znvuser.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('znvuser', $this->Znvuser->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Znvuser->create();
			if ($this->Znvuser->save($this->data)) {
				$this->Session->setFlash(__('The Znvuser has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Znvuser could not be saved. Please, try again.', true));
			}
		}
		$donvis = $this->Znvuser->Donvi->find('list');
		$chucdanhs = $this->Znvuser->Chucdanh->find('list');
		$users = $this->Znvuser->User->find('list');
		$this->set(compact('donvis', 'chucdanhs', 'users'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid Znvuser', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->Znvuser->save($this->data)) {
				$this->Session->setFlash(__('The Znvuser has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The Znvuser could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Znvuser->read(null, $id);
		}
		$donvis = $this->Znvuser->Donvi->find('list');
		$chucdanhs = $this->Znvuser->Chucdanh->find('list');
		$users = $this->Znvuser->User->find('list');
		$this->set(compact('donvis','chucdanhs','users'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for Znvuser', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->Znvuser->del($id)) {
			$this->Session->setFlash(__('Znvuser deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>